.TH std::experimental::filesystem::path::replace_extension 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::experimental::filesystem::path::replace_extension \- std::experimental::filesystem::path::replace_extension

.SH Synopsis
   path& replace_extension( const path& replacement = path() ); \fB(1)\fP (filesystem TS)

   Replaces the extension with replacement or removes it when the default value of
   replacement is used.

   Firstly, if this path has an extension(), it is removed.

   Then, a dot character is appended if replacement is not empty or does not begin with
   a dot character.

   Then replacement is appended to the path.

.SH Parameters

   replacement - the extension to replace with

.SH Return value

   *this

.SH Exceptions

   May throw implementation-defined exceptions.

.SH Example


// Run this code

 #include <experimental/filesystem>
 #include <iostream>
 namespace fs = std::experimental::filesystem;

 int main()
 {
     fs::path p = "/foo/bar.jpeg";
     std::cout << "Was: " << p << '\\n';
     p.replace_extension(".jpg");
     std::cout << "Now: " << p << '\\n';
 }

.SH Output:

 Was: "/foo/bar.jpeg"
 Now: "/foo/bar.jpg"

.SH See also

   extension     returns the file extension path component
                 \fI(public member function)\fP
   filename      returns the filename path component
                 \fI(public member function)\fP
   stem          returns the stem path component
                 \fI(public member function)\fP
   has_extension checks if the corresponding path element is not empty
                 \fI(public member function)\fP

.SH Category:
     * Noindexed pages
